// // --------------------------------------------------------------------------------------------------------------------
// // <copyright file="LicensingForm.cs" company="Collaboris">
// //   Copyright Collaboris
// // </copyright>
// // <summary>
// //   
// // </summary>
// // --------------------------------------------------------------------------------------------------------------------

namespace DocRead.Selenium.Tests.DocRead.ControlObjects
{
    #region

    using Collaboris.ShareTest.Core;
    using Collaboris.ShareTest.SharePoint2010.ControlObjects;

    using OpenQA.Selenium;
    using OpenQA.Selenium.Remote;

    #endregion

    public class LicensingForm : SPTModelBase
    {
        #region Constants and Fields

        public static string CtrlAddKeyButton = "ctl00_PlaceHolderMain_LicenseKeySection_AddKeyButton";

        public static string CtrlCancelButton = "ctl00_PlaceHolderMain_ctl00_BtnCancel";

        public static string CtrlLicenseKeyId = "ctl00_PlaceHolderMain_LicenseKeySection_LicenseKeyTextBox";

        public static string CtrlLicenseStatusId = "ctl00_PlaceHolderMain_LicenseSection_LicenseStatusValue";

        public static string CtrlLicensedToId = "ctl00_PlaceHolderMain_LicenseSection_LicensedToValue";

        public static string CtrlModulesId = "ctl00_PlaceHolderMain_LicenseSection_ProductModulesValue";

        public static string CtrlNumberOfDaysUsedId = "ctl00_PlaceHolderMain_LicenseSection_NumberOfDaysValue";

        public static string CtrlNumberOfUsersId = "ctl00_PlaceHolderMain_LicenseSection_NumberOfUsersValue";

        public static string CtrlProductNameId = "ctl00_PlaceHolderMain_LicenseSection_ProductNameValue";

        public static string CtrlRemainDaysId = "ctl00_PlaceHolderMain_LicenseSection_LeftoverDaysValue";

        public static string CtrlSerialNumberId = "ctl00_PlaceHolderMain_LicenseSection_SerialNumberValue";

        public static string CtrlVersionId = "ctl00_PlaceHolderMain_LicenseSection_VersionValue";

        public static string CtrlNumberOfSitesid = "ctl00_PlaceHolderMain_LicenseSection_NumberOfSitesValue";

        #endregion

        #region Constructors and Destructors

        public LicensingForm(RemoteWebDriver driver)
            : base(driver)
        {
        }

        #endregion

        #region Public Properties

        public IWebElement CancelButton
        {
            get
            {
                return this.WebDriver.FindElementById(CtrlCancelButton);
            }
        }

        public string LicenseKey { get; set; }

        /// <summary>
        /// 	LicenseKey Element
        /// </summary>
        public IWebElement LicenseKeyElement
        {
            get
            {
                return this.WebDriver.FindElementById(CtrlLicenseKeyId);
            }
        }

        public string LicenseStatus { get; set; }

        /// <summary>
        /// 	LicenseStatus Element
        /// </summary>
        public IWebElement LicenseStatusElement
        {
            get
            {
                return this.WebDriver.FindElementById(CtrlLicenseStatusId);
            }
        }

        public string LicensedTo { get; set; }

        /// <summary>
        /// 	LicensedTo Element
        /// </summary>
        public IWebElement LicensedToElement
        {
            get
            {
                return this.WebDriver.FindElementById(CtrlLicensedToId);
            }
        }

        public string Modules { get; set; }

        /// <summary>
        /// 	Modules Element
        /// </summary>
        public IWebElement ModulesElement
        {
            get
            {
                return this.WebDriver.FindElementById(CtrlModulesId);
            }
        }

        public string NumberOfDaysUsed { get; set; }

        /// <summary>
        /// 	NumberOfDaysUsed Element
        /// </summary>
        public IWebElement NumberOfDaysUsedElement
        {
            get
            {
                return this.WebDriver.FindElementById(CtrlNumberOfDaysUsedId);
            }
        }

        
        public string NumberOfUsers { get; set; }

        /// <summary>
        /// 	NumberOfUsers Element
        /// </summary>
        public IWebElement NumberOfUsersElement
        {
            get
            {
                return this.WebDriver.FindElementById(CtrlNumberOfUsersId);
            }
        }

       
        public IWebElement AddButton
        {
            get
            {
                return this.WebDriver.FindElementById(CtrlAddKeyButton);
            }
        }

        public string ProductName { get; set; }

        /// <summary>
        /// 	ProductName Element
        /// </summary>
        public IWebElement ProductNameElement
        {
            get
            {
                return this.WebDriver.FindElementById(CtrlProductNameId);
            }
        }

        

        public string RemainDays { get; set; }

        /// <summary>
        /// 	RemainDays Element
        /// </summary>
        public IWebElement RemainDaysElement
        {
            get
            {
                return this.WebDriver.FindElementById(CtrlRemainDaysId);
            }
        }

        
        public string SerialNumber { get; set; }

        /// <summary>
        /// 	SerialNumber Element
        /// </summary>
        public IWebElement SerialNumberElement
        {
            get
            {
                return this.WebDriver.FindElementById(CtrlSerialNumberId);
            }
        }

        public string NumberOfSiteCollections { get; set; }

        public IWebElement NumberSitesElement
        {
            get
            {
                return this.WebDriver.FindElementById(CtrlNumberOfSitesid);
            }
        }
        
        public string TopLevelError { get; set; }

        public IWebElement TopLevelErrorElement
        {
            get
            {
                return this.WebDriver.IsElementPresent(By.XPath(Locators.XpathTopLevelErrorIdentifier))
                           ? this.WebDriver.FindElementByXPath(Locators.XpathTopLevelErrorIdentifier)
                           : null;
            }
        }

        public string Version { get; set; }

        /// <summary>
        /// 	Version Element
        /// </summary>
        public IWebElement VersionElement
        {
            get
            {
                return this.WebDriver.FindElementById(CtrlVersionId);
            }
        }

        #endregion

        #region Public Methods

        public void RefreshForm()
        {
            // titles
            this.LicenseKey = this.LicenseKeyElement.GetAttribute("value");
            this.ProductName = this.ProductNameElement.Text;
            this.Version = this.VersionElement.Text;
            this.SerialNumber = this.SerialNumberElement.Text;
            this.LicensedTo = this.LicensedToElement.Text;
            this.NumberOfUsers = this.NumberOfUsersElement.Text;
            this.LicenseStatus = this.LicenseStatusElement.Text;
            this.RemainDays = this.RemainDaysElement.Text;
            this.NumberOfDaysUsed = this.NumberOfDaysUsedElement.Text;
            this.Modules = this.ModulesElement.Text;
            this.NumberOfSiteCollections = this.NumberSitesElement.Text;

            

            // errors
            if (this.TopLevelErrorElement != null)
            {
                this.TopLevelError = this.TopLevelErrorElement.Text;
            }
        }

        

        #endregion
    }
}